package xupt.com.bolg.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xupt.com.bolg.entity.Dot;
import xupt.com.bolg.repository.DotRepository;
import xupt.com.bolg.service.DotService;

import java.util.List;
import java.util.Optional;

@Service
public class DotServiceImpl implements DotService {
    @Autowired
    DotRepository dotRepository;
    @Override
    public Dot findByID(Integer id) {
        Optional<Dot> byId = dotRepository.findById(id);
        return byId.get();
    }

    @Override
    public boolean saveDot(Dot dot) {
        dotRepository.save(dot);
        return true;
    }

    @Override
    public Dot findDot(Integer bolgid, Integer userid) {
        List<Dot> all = dotRepository.findAll();
        for(int i=0;i<all.size();i++){
            Dot dot = all.get(i);
            if(dot.getMeid()==userid&&dot.getHeid()==bolgid){
                return dot;
            }
        }
        return null;
    }
}
